﻿@using DealerJudge.Entity;
@using DealerJudge.Web.Helpers;

@model  DealerJudge.Web.Models.HomeModel
            

@{
    ViewBag.Title = "Dealer Judge - Home Page";
    
    //List<DealerJudge.Entity.Category> categoryList = Model.GetDealerCategory();
}

<script type="text/javascript">
    function js_populateManufacturer() {
        var var_city_id = $("#cmbCity").val();
        var var_cat_id = $("#catRadio").val();
        //var city_name = $("#cmbCity").Text();
        window.alert(" call cascading dropdown for category = " + var_cat_id);
        //window.alert(" call cascading dropdown for city = " + var_city_id);

        //var urlManufacturer = 'Url.Action("GetManufacturerForCityAndCategory", new {city_id=' + var_city_id + ', cat_id=1})';
        var dummyurlManufacturer = '@Url.Action("GetManufacturerForCityAndCategory", new {city_id=-1, cat_id=1})';
        var urlManufacturer = dummyurlManufacturer.replace("-1", var_city_id);
        var select = $('#cmbM');

        $.ajax({
            type: "POST",
            url: urlManufacturer,
            data: JSON.stringify(2, 0),
            datatype: "JSON",
            contentType: "application/json; charset=utf-8",
            success: function (returndata) {
                if (returndata.ok) {
                    //window.alert('Manufacturer data  is on javascript,  populating combo ');
                    select.empty();
                    
                    $.each(returndata.data, function (index, itemData) {
                        select.append($('<option></option>').val(itemData.Id).html(itemData.Name));
                    });
                    select.show('slow');
                    select.change();
                }
                else {
                    window.alert(' error : ' + returndata.message);
                }
            }
        }
        );
    }
</script>

<div id="divReviewSearchSteps" style="width: 100%; border: 2px;">
    <table style="width:100%">
        <tr>
            <td>
                <h2>Step 1</h2>
            </td>
            <td>
                 <h2>Step 2</h2>
            </td>
        </tr>
        <tr>
            <td style="width:50%">
                    <br /> <br />

                    <div>
                        <h3>Select Type </h3>
                        @Html.RadioButton("SearchType", "1") Dealer 
                        @Html.RadioButton("SearchType", "2") Service Centers
                    </div>
                    
                    <br /> <br />

                    @*Html.Label(Model.var_cL[0].Name)*@
                    @*Choose Category: @Html.DropDownList("categoryList")*@

                    <h3>Choose Category</h3>

                    @foreach (Category category in ViewBag.categoryList)
                    {
                        @Html.RadioButtonFor(x => category.Name, category.Id, new { @id = "catRadio" } ); 
                        @Html.Label(category.Name);
                        <br />                   
                    }

                    @*foreach (City city in ViewBag.ListCity){
                            @Html.Label(city.Name);
                            <br />
                    }*@
                    
                    @*
                    @foreach (City city in (List<City>)ViewData["cityList1"])
                    {
                            @Html.Label(city.Name);
                            <br />
                        <br />
                    }*@

            </td>
            <td>
                <br /><br />
                <div>
                    <table>
                        <tr>
                            <td>
                                <h3>City</h3>
                            </td>
                            <td>
                                @Html.DropDownList("cmbCity", (IEnumerable<SelectListItem>)ViewData["cityListByCategory"], new { @onchange = "javascript:js_populateManufacturer()" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h3>Manufacturer</h3>
                            </td>
                            <td>
                                @*Html.DropDownList("ManufacturerListByCategoryAndCity")*@
                                <select id="cmbM"> </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h3>Location</h3>
                            </td>
                            <td>
                                @Html.TextBox("txtLocation")
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @* Empty *@
                            </td>
                            <td>
                                @*Html.Button("Blah", "bla")*@
                                <input type=submit id="btnSearchHome" name="Search" />
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>
</div>
